```html
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Java静态变量与成员变量详解</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
            color: #333;
            line-height: 1.6;
        }
        .hero {
            background: linear-gradient(135deg, #6e8efb 0%, #a777e3 100%);
        }
        .card {
            transition: all 0.3s ease;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .card:hover {
            transform: translateY(-5px);
            box-shadow: 0 10px 20px rgba(0, 0, 0, 0.15);
        }
        .highlight {
            position: relative;
            z-index: 1;
        }
        .highlight::before {
            content: '';
            position: absolute;
            left: 0;
            bottom: 0;
            width: 100%;
            height: 30%;
            background-color: rgba(110, 142, 251, 0.2);
            z-index: -1;
            transition: all 0.3s ease;
        }
        .highlight:hover::before {
            height: 100%;
        }
        .mermaid {
            background-color: #fff;
            border-radius: 0.5rem;
            padding: 2rem;
            margin: 2rem 0;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
        }
        .comparison-table {
            border-collapse: separate;
            border-spacing: 0;
            border-radius: 0.5rem;
            overflow: hidden;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }
        .comparison-table th, .comparison-table td {
            padding: 1rem;
            text-align: left;
            border-bottom: 1px solid #e2e8f0;
        }
        .comparison-table th {
            background-color: #4a5568;
            color: white;
            font-weight: 500;
        }
        .comparison-table tr:nth-child(even) {
            background-color: #f7fafc;
        }
        .comparison-table tr:hover {
            background-color: #ebf8ff;
        }
        .dropcap::first-letter {
            float: left;
            font-size: 3.5rem;
            line-height: 3rem;
            padding-right: 0.5rem;
            margin-top: 0.25rem;
            font-weight: bold;
            color: #4a5568;
        }
        .footer-link {
            transition: all 0.2s ease;
        }
        .footer-link:hover {
            color: #a777e3;
            transform: translateX(3px);
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="hero text-white py-20 md:py-32 px-4 md:px-0">
        <div class="container mx-auto max-w-5xl flex flex-col items-center text-center">
            <div class="w-20 h-20 mb-6 rounded-full bg-white bg-opacity-20 flex items-center justify-center">
                <i class="fas fa-code text-3xl"></i>
            </div>
            <h1 class="text-4xl md:text-5xl font-bold mb-4 font-serif">Java变量解析</h1>
            <h2 class="text-xl md:text-2xl mb-8 opacity-90">静态变量与成员变量的深度对比</h2>
            <p class="text-lg max-w-3xl leading-relaxed opacity-90">
                探索Java中两种核心变量的本质区别，了解它们的内存分配、生命周期以及最佳使用场景，提升您的编程设计能力。
            </p>
        </div>
    </section>

    <!-- Main Content -->
    <main class="container mx-auto max-w-5xl px-4 md:px-0 py-12">
        <!-- Introduction -->
        <section class="mb-16">
            <p class="dropcap text-lg text-gray-700 leading-relaxed">
                在Java编程中，静态变量(Static Variable)和成员变量(Instance Variable)是两种基础但重要的变量类型。它们虽然在声明方式上相似，但在内存分配、生命周期和使用场景上有着显著差异。理解这些差异对于编写高效、可维护的Java代码至关重要。
            </p>
        </section>

        <!-- Comparison Table -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-balance-scale mr-3 text-purple-600"></i>
                <span class="highlight">核心区别对比</span>
            </h2>
            
            <div class="overflow-x-auto">
                <table class="comparison-table w-full">
                    <thead>
                        <tr>
                            <th class="w-1/4">比较维度</th>
                            <th class="w-2/4">静态变量 (Static Variable)</th>
                            <th class="w-2/4">成员变量 (Instance Variable)</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                            <td><strong>定义与声明</strong></td>
                            <td>使用 <code>static</code> 关键字修饰，属于类本身</td>
                            <td>不使用 <code>static</code> 关键字，属于对象实例</td>
                        </tr>
                        <tr>
                            <td><strong>内存分配</strong></td>
                            <td>类加载时分配，内存中只有一份</td>
                            <td>对象创建时分配，每个对象独立一份</td>
                        </tr>
                        <tr>
                            <td><strong>存储位置</strong></td>
                            <td>方法区的静态存储区</td>
                            <td>堆内存中</td>
                        </tr>
                        <tr>
                            <td><strong>生命周期</strong></td>
                            <td>与类相同，从类加载到卸载</td>
                            <td>与对象相同，从创建到垃圾回收</td>
                        </tr>
                        <tr>
                            <td><strong>访问方式</strong></td>
                            <td>通过类名或对象访问（推荐类名）</td>
                            <td>必须通过对象访问</td>
                        </tr>
                        <tr>
                            <td><strong>默认初始值</strong></td>
                            <td colspan="2" class="text-center">相同（整数0，布尔false，引用null）</td>
                        </tr>
                        <tr>
                            <td><strong>线程安全</strong></td>
                            <td>共享变量，可能有线程安全问题</td>
                            <td>对象级别，相对更易保证线程安全</td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </section>

        <!-- Memory Diagram -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-memory mr-3 text-blue-600"></i>
                <span class="highlight">内存分配示意图</span>
            </h2>
            
            <div class="mermaid">
                classDiagram
                    class ClassName {
                        <<Class>>
                        +static staticVariable: int
                    }
                    
                    class Object1 {
                        <<Instance>>
                        +instanceVariable: int
                    }
                    
                    class Object2 {
                        <<Instance>>
                        +instanceVariable: int
                    }
                    
                    ClassName --|> Object1
                    ClassName --|> Object2
                    
                    note for ClassName "静态变量存储在方法区\n所有实例共享同一份"
                    note for Object1 "成员变量存储在堆中\n每个实例有自己的拷贝"
            </div>
        </section>

        <!-- Detailed Explanation -->
        <section class="grid grid-cols-1 md:grid-cols-2 gap-8 mb-16">
            <!-- Static Variable Card -->
            <div class="card bg-white p-6 rounded-lg">
                <div class="flex items-center mb-4">
                    <div class="w-12 h-12 rounded-full bg-blue-100 flex items-center justify-center mr-4">
                        <i class="fas fa-cubes text-blue-600 text-xl"></i>
                    </div>
                    <h3 class="text-2xl font-bold text-blue-800">静态变量</h3>
                </div>
                <div class="space-y-4">
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-code mr-2 text-blue-500"></i>
                            定义方式
                        </h4>
                        <pre class="bg-gray-100 p-3 rounded text-sm overflow-x-auto"><code>public class Example {
    // 静态变量定义
    public static int count = 0;
}</code></pre>
                    </div>
                    
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-microchip mr-2 text-blue-500"></i>
                            内存特点
                        </h4>
                        <p class="text-gray-700">
                            静态变量在类加载时分配内存，整个JVM中只有一份，所有对象实例共享同一内存区域。这使其非常适合用于实现计数器、配置参数等需要全局共享的数据。
                        </p>
                    </div>
                    
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-exclamation-triangle mr-2 text-blue-500"></i>
                            注意事项
                        </h4>
                        <ul class="list-disc pl-5 text-gray-700 space-y-1">
                            <li>多线程访问时需要考虑同步问题</li>
                            <li>过度使用会破坏面向对象的封装性</li>
                            <li>可能导致内存泄漏风险</li>
                        </ul>
                    </div>
                </div>
            </div>
            
            <!-- Instance Variable Card -->
            <div class="card bg-white p-6 rounded-lg">
                <div class="flex items-center mb-4">
                    <div class="w-12 h-12 rounded-full bg-purple-100 flex items-center justify-center mr-4">
                        <i class="fas fa-cube text-purple-600 text-xl"></i>
                    </div>
                    <h3 class="text-2xl font-bold text-purple-800">成员变量</h3>
                </div>
                <div class="space-y-4">
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-code mr-2 text-purple-500"></i>
                            定义方式
                        </h4>
                        <pre class="bg-gray-100 p-3 rounded text-sm overflow-x-auto"><code>public class Example {
    // 成员变量定义
    private String name;
    private int age;
}</code></pre>
                    </div>
                    
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-microchip mr-2 text-purple-500"></i>
                            内存特点
                        </h4>
                        <p class="text-gray-700">
                            成员变量在对象实例化时分配内存，每个对象都有自己独立的一份拷贝。这意味着不同对象的成员变量相互独立，互不影响。
                        </p>
                    </div>
                    
                    <div>
                        <h4 class="font-semibold text-gray-800 mb-2 flex items-center">
                            <i class="fas fa-exclamation-triangle mr-2 text-purple-500"></i>
                            注意事项
                        </h4>
                        <ul class="list-disc pl-5 text-gray-700 space-y-1">
                            <li>封装性原则：通常设为private并提供访问方法</li>
                            <li>合理使用final关键字保证线程安全</li>
                            <li>考虑使用不可变对象设计模式</li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>

        <!-- Usage Scenarios -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-lightbulb mr-3 text-yellow-600"></i>
                <span class="highlight">应用场景与最佳实践</span>
            </h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div class="bg-blue-50 p-6 rounded-lg border-l-4 border-blue-500">
                    <h3 class="text-xl font-bold text-blue-800 mb-3">静态变量适用场景</h3>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>共享常量（如数学常数、配置参数）</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>对象计数器（统计实例数量）</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>工具类中的辅助方法</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-blue-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>缓存常用数据（需考虑线程安全）</span>
                        </li>
                    </ul>
                </div>
                
                <div class="bg-purple-50 p-6 rounded-lg border-l-4 border-purple-500">
                    <h3 class="text-xl font-bold text-purple-800 mb-3">成员变量适用场景</h3>
                    <ul class="space-y-2 text-gray-700">
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>对象状态（如用户姓名、年龄）</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>聚合关系（如订单中的商品列表）</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>依赖注入的对象实例</span>
                        </li>
                        <li class="flex items-start">
                            <i class="fas fa-check-circle text-purple-500 mt-1 mr-2 flex-shrink-0"></i>
                            <span>需要线程隔离的状态数据</span>
                        </li>
                    </ul>
                </div>
            </div>
            
            <div class="mt-8 bg-yellow-50 p-6 rounded-lg border-l-4 border-yellow-500">
                <h3 class="text-xl font-bold text-yellow-800 mb-3 flex items-center">
                    <i class="fas fa-exclamation-triangle mr-2"></i>
                    设计建议
                </h3>
                <div class="text-gray-700 space-y-3">
                    <p>1. <strong>最小化静态变量使用</strong>：仅在真正需要共享数据时使用静态变量，避免滥用导致代码难以维护。</p>
                    <p>2. <strong>区分常量与变量</strong>：对于不会改变的值，使用<code>static final</code>声明为常量，而非普通静态变量。</p>
                    <p>3. <strong>考虑线程安全</strong>：静态变量在多线程环境下需要同步保护，而成员变量可以通过对象隔离提高线程安全性。</p>
                    <p>4. <strong>封装性原则</strong>：成员变量通常应设为private，通过getter/setter方法控制访问。</p>
                </div>
            </div>
        </section>

        <!-- Code Example -->
        <section class="mb-16">
            <h2 class="text-3xl font-bold mb-8 flex items-center">
                <i class="fas fa-laptop-code mr-3 text-green-600"></i>
                <span class="highlight">代码示例</span>
            </h2>
            
            <div class="grid grid-cols-1 md:grid-cols-2 gap-6">
                <div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">静态变量示例</h3>
                    <pre class="bg-gray-100 p-4 rounded-lg text-sm overflow-x-auto"><code>public class Car {
    // 静态变量 - 记录创建的Car实例总数
    public static int totalCars = 0;
    
    // 成员变量 - 每辆车的独特属性
    private String model;
    private String color;
    
    public Car(String model, String color) {
        this.model = model;
        this.color = color;
        totalCars++;  // 每创建一辆车，计数器+1
    }
    
    public static void main(String[] args) {
        Car car1 = new Car("Toyota", "Red");
        Car car2 = new Car("Honda", "Blue");
        
        System.out.println("Total cars: " + Car.totalCars);  // 输出2
    }
}</code></pre>
                </div>
                
                <div>
                    <h3 class="text-xl font-semibold mb-3 text-gray-800">成员变量示例</h3>
                    <pre class="bg-gray-100 p-4 rounded-lg text-sm overflow-x-auto"><code>public class BankAccount {
    // 成员变量 - 每个账户的独立状态
    private String accountNumber;
    private double balance;
    private String ownerName;
    
    public BankAccount(String accountNumber, 
                      double initialBalance, 
                      String ownerName) {
        this.accountNumber = accountNumber;
        this.balance = initialBalance;
        this.ownerName = ownerName;
    }
    
    public void deposit(double amount) {
        if (amount > 0) {
            balance += amount;
        }
    }
    
    public void withdraw(double amount) {
        if (amount > 0 && balance >= amount) {
            balance -= amount;
        }
    }
    
    // 其他方法...
}</code></pre>
                </div>
            </div>
        </section>

        <!-- Summary -->
        <section class="bg-gray-100 p-8 rounded-lg mb-16">
            <h2 class="text-3xl font-bold mb-6 text-center text-gray-800">核心要点总结</h2>
            <div class="grid grid-cols-1 md:grid-cols-3 gap-6">
                <div class="bg-white p-4 rounded-lg shadow-sm text-center">
                    <div class="w-16 h-16 bg-blue-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-project-diagram text-blue-500 text-2xl"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">归属关系</h3>
                    <p class="text-gray-700">静态变量属于类，成员变量属于对象实例</p>
                </div>
                
                <div class="bg-white p-4 rounded-lg shadow-sm text-center">
                    <div class="w-16 h-16 bg-purple-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-memory text-purple-500 text-2xl"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">内存分配</h3>
                    <p class="text-gray-700">静态变量只有一份，成员变量每个对象独立</p>
                </div>
                
                <div class="bg-white p-4 rounded-lg shadow-sm text-center">
                    <div class="w-16 h-16 bg-green-100 rounded-full flex items-center justify-center mx-auto mb-4">
                        <i class="fas fa-clock text-green-500 text-2xl"></i>
                    </div>
                    <h3 class="font-semibold text-lg mb-2">生命周期</h3>
                    <p class="text-gray-700">静态变量随类存在，成员变量随对象存在</p>
                </div>
            </div>
        </section>
    </main>

    <!-- Footer -->
    <footer class="bg-gray-900 text-gray-300 py-10">
        <div class="container mx-auto max-w-5xl px-4 md:px-0 text-center">
            <div class="flex flex-col md:flex-row justify-center items-center space-y-4 md:space-y-0 md:space-x-8">
                <div class="flex items-center">
                    <i class="fas fa-laptop-code text-xl mr-2 text-purple-400"></i>
                    <span class="text-lg font-medium">技术小馆</span>
                </div>
                <div>
                    <a href="http://www.yuque.com/jtostring" class="footer-link hover:text-white flex items-center justify-center">
                        <i class="fas fa-external-link-alt mr-2"></i>
                        <span>http://www.yuque.com/jtostring</span>
                    </a>
                </div>
            </div>
            <div class="mt-6 text-sm text-gray-500">
                &copy; 2023 技术小馆. 版权所有.
            </div>
        </div>
    </footer>

    <script>
        mermaid.initialize({
            startOnLoad: true,
            theme: 'default',
            fontFamily: '"Noto Sans SC", sans-serif',
            flowchart: {
                useMaxWidth: true,
                htmlLabels: true,
                curve: 'basis'
            }
        });
    </script>
</body>
</html>
```